/***********************************************************************
 * Module:  NurseDto.java
 * Author:  Vanil
 * Purpose: Defines the Class NurseDto
 ***********************************************************************/
package Personal;
import DB.dao.*;
import DB.dto.*;
import DB.exceptions.*;
import DB.jdbc.*;
import Process.*;
import Hosp.Department;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

public class Nurse extends Person {


   private NurseDto dto;

   public void viewAllTasks() {
      // TODO: implement
   }

    public Nurse() {
    }

    public NurseDto getDto() {
        return dto;
    }

    public Nurse(NurseDto dto) {
        this.dto = dto;
    }
    public java.util.Collection<Patient> getPatients() throws PersonDaoException, PatientDaoException {
       int idNurse = ((NurseDto)dto).getIdNurse();
       PatientDao dao = new PatientDaoImpl();
       PatientDto[] patientDtos = dao.findByNurse(idNurse);
       Collection<Patient> patients = new HashSet<Patient>();
       for(PatientDto patDto:patientDtos)
       {
           patients.add(new Patient(patDto));
       }
      return patients;
   }

   /** @pdGenerated default add
     * @param newPatient */
   public void addPatient(Patient newPatient) throws PatientDaoException {
       if(newPatient!=null)
         newPatient.setNurse(this);
   }

   /** @pdGenerated default remove
     * @param oldPatient */
   public void removePatient(Patient oldPatient) throws PatientDaoException {
      if (oldPatient != null)
            oldPatient.setNurse((Nurse)null);

   }
   /** @pdGenerated default getter */
   public java.util.Collection<Operation> getOperations() throws OperationDaoException {
      OperationDao dao = new OperationDaoImpl();
       OperationDto[] operationDtos = dao.findByNurse(this.dto.getIdPerson());
       Collection<Operation> list = new ArrayList<Operation>();
       for(OperationDto dto :operationDtos)
       {
           list.add(new Operation(dto));
       }
       return list;
   }
   /** @pdGenerated default parent getter */
   public Department getDepartment() throws DepartmentDaoException {
       int idDepartment = ((NurseDto) dto).getIdDepartment();
       DepartmentDao dao = new DepartmentDaoImpl();
       return new Department(dao.findByPrimaryKey(idDepartment));

   }

   /** @pdGenerated default parent setter
     * @param newDepartment */
   public void setDepartment(Department newDepartment) throws PersonDaoException {
      ((NurseDto)this.dto).setIdDepartment(newDepartment.getIdDepartment());
       dao.update(dto.getIdPerson(),dto);
   }


    @Override
    public String toString() {
        return super.toString();    //To change body of overridden methods use File | Settings | File Templates.
       // return "Nurse "+this.name+" exp: "+ this.exp + " Speciality "+this.speciality;
    }

}